import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Edge()
driver.get("https://www.zhipin.com/")
driver.find_element(By.CSS_SELECTOR, "#wrap > div.column-search-panel.search-panel-new > div > div.search-box > div.search-form > form > div.search-form-con > p > input").send_keys("大数据开发工程师")
driver.find_element(By.CSS_SELECTOR, "#wrap > div.column-search-panel.search-panel-new > div > div.search-box > div.search-form > form > button").click()
time.sleep(15)
num = 1

with open("D:/JetBrains Projects/Pycharm Projects/python-learn/爬虫作业/boss直聘/boss直聘.txt", "a", encoding="UTF-8") as f:
    for i in range(2):
        mylist = driver.find_elements(By.CSS_SELECTOR, ".search-job-result ul li")
        for li in mylist:
            try:
                llist = [
                    "工作岗位：" + li.find_element(By.CSS_SELECTOR, ".job-title.clearfix .job-name").text,
                    "工作地址：" + li.find_element(By.CSS_SELECTOR, ".job-title.clearfix .job-area").text,
                    "工作薪资：" + li.find_element(By.CSS_SELECTOR, ".job-info.clearfix .salary").text,
                    "工作要求：" + li.find_element(By.CSS_SELECTOR, ".job-info.clearfix .tag-list").text.replace("\n", "，"),
                    "招聘人员：" + li.find_element(By.CSS_SELECTOR, ".job-info.clearfix .info-public").text,
                    "公司名字：" + li.find_element(By.CSS_SELECTOR, ".job-card-right .company-name").text,
                    "公司信息：" + li.find_element(By.CSS_SELECTOR, ".job-card-right ul").text,
                    "工作对象：" + li.find_element(By.CSS_SELECTOR, ".job-card-footer.clearfix ul").text,
                    "工作福利：" + li.find_element(By.CSS_SELECTOR, ".job-card-footer.clearfix .info-desc").text
                ]
                f.write(f"第{num}个职业\n"+"\n".join(llist))
                f.write("\n\n")
                num += 1
            except:
                pass
        driver.find_element(By.CSS_SELECTOR, "#wrap > div.page-job-wrapper > div.page-job-inner > div > div.job-list-wrapper > div.search-job-result > div > div > div > a:nth-child(10)").click()
        time.sleep(15)
